package com.hzhr.iot.user.dao;

import com.hzhr.iot.user.dao.mapper.custom.UserEntityCustomMapper;
import com.hzhr.iot.user.dao.mapper.generator.UserEntityMapper;
import com.hzhr.iot.user.entity.UserEntity;
import com.hzhr.iot.user.entity.ext.UserEntityExt;
import com.hzhr.iot.user.queryModel.custom.UserCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class UserDao {
    @Autowired
    UserEntityMapper userEntityMapper;
    @Autowired
    UserEntityCustomMapper userEntityCustomMapper;

    public int insert(UserEntity record) {
        if (record == null) return 0;
        int changeCount = userEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(UserCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = userEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(UserEntity record) {
        if (record == null) return 0;
        int changeCount = userEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(UserCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = userEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public UserEntity selectEntity(UserCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<UserEntityExt> extList = userEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<UserEntity> selectEntityList(UserCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<UserEntityExt> extList = userEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<UserEntity> entityList = new ArrayList<>();
        for (UserEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public UserEntityExt selectExt(UserCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<UserEntityExt> extList = userEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<UserEntityExt> selectExtList(UserCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<UserEntityExt> extList = userEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public int selectCount(UserCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = userEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
